package com.wangbo.delayQueue;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * 延时任务
 */
public class DelayTask implements Delayed {
    public Long expiration;  // 过期时间
    public Integer bizType;  // 业务内容
    public Object param;  // 任务参数

    public DelayTask(long expiration, int bizType, Object param) {
        this.expiration = expiration;
        this.bizType = bizType;
        this.param = param;
    }

    @Override
    public long getDelay(TimeUnit unit) {
        return unit.convert(this.expiration - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(Delayed o) {
        DelayTask delayTask = (DelayTask) o;
        return this.expiration <= delayTask.expiration ? -1 : 1;
    }
}
